$(function () {
    vm.getnumber();
    $("#jqGrid").jqGrid({
        url: baseURL + 'gaokaobaobei/userbackup/list',
        datatype: "json",
        colModel: [
			{ label: '姓名', name: 'name', index: 'name', width: 80 }, 			
			{ label: '考号', name: 'candidateNumber', index: 'candidate_number', width: 150 ,
                formatter: function (data,a,rows) {
				if(rows.type=='等待录取结果'){

                    return `${data}<br>录取学校:<input id="xuexiao${data}" /><br>录取专业: <input id="zhuanye${data}" />`;
                }else {

					return `${data}`
				}

                } }, 			
			{ label: '文理属性', name: 'wlProperty', index: 'wl_property', width: 80 }, 			
			{ label: '分数', name: 'score', index: 'score', width: 80 }, 			
			{ label: '毕业高中', name: 'highSchool', index: 'high_school', width: 80 },
			{ label: '联系电话', name: 'phone', index: 'phone', width: 80 },
            { label: '操作', name: 'cz', index: 'cz', width: 80,
                formatter: function (data,a,rows) {

                    if(rows.type=='等待录取结果'){
                        return '<button style="width: 100px;height: 30px" class="label label-default" onclick="baobei(\''+rows.candidateNumber+'\')">提交审核</button>';

                    }else if(rows.type=='等待审核'){
                        return `<font color="#ffd700">审核中</font>`
                    }else if(rows.type=='审核通过'){
                        return `<font color="#228b22">审核通过</font>`
                    }else if(rows.type=='已过期'){
                        return `<font color="red">已过期</font>`
                    }

                } },
            { label: '状态', name: 'type', index: 'type', width: 80 },
			{ label: '报备时间', name: 'creationDate', index: 'creation_date', width: 80 }			
        ],
		viewrecords: true,
        height: 385,
        rowNum: 10,
		rowList : [10,30,50],
        rownumbers: false,
        rownumWidth: 25, 
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page",
            rows:"limit", 
            order: "order"
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	//$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" });
        }
    });
});
function baobei(data1) {
	var school = $(`#xuexiao`+data1).val();
  	var zhuanye = $(`#zhuanye`+data1).val();
  	if (school =="" || school == null){
  		alert("请填入录取院校");
  		return ;
	}
    if (zhuanye =="" || zhuanye == null){
        alert("请填入录取专业");
        return ;
    }
	var data = "school="+school+"&zhuanye="+zhuanye+"&number="+data1;
    var url = "gaokaobaobei/userbackup/baobei";
    $.ajax({
        type: "POST",
        url: baseURL + url,
        data: data,
        success: function(r){
        	if(r.flag){
                alert("报备成功~")
                vm.reload();
            } else {
                alert("报备失败了~请完善你的报备信息")
			}
        }
    });
}
var vm = new Vue({
	el:'#rrapp',
	data:{
		showList: true,
		title: null,
		userBackup: {},
		number:"",
		type:null,
		typeID:null
	},
	methods: {
		getnumber:function () {

            var url = "gaokaobaobei/userbackup/getNumber";
            $.ajax({
                type: "POST",
                url: baseURL + url,
                success: function(r){
                      vm.number = r.number;
                }
            });

        },
		query: function () {
			vm.reload();
		},
		add: function(){
			vm.showList = false;
			vm.title = "新增";
			vm.userBackup = {};
		},
		update: function (event) {
			var id = getSelectedRow();
			if(id == null){
				return ;
			}
			vm.showList = false;
            vm.title = "修改";
            
            vm.getInfo(id)
		},

		saveOrUpdate: function (event) {
			var url = vm.userBackup.id == null ? "gaokaobaobei/userbackup/save?typeID="+vm.typeID : "gaokaobaobei/userbackup/update";
			$.ajax({
				type: "POST",
			    url: baseURL + url,
                contentType: "application/json",
			    data: JSON.stringify(vm.userBackup),
			    success: function(r){
			    	if(r.code === 0){
						alert('操作成功', function(index){
							vm.reload();
						});
					}else{
						alert(r.msg);
					}
				}
			});
		},
		del: function (event) {
			var ids = getSelectedRows();
			if(ids == null){
				return ;
			}
			
			confirm('确定要删除选中的记录？', function(){
				$.ajax({
					type: "POST",
				    url: baseURL + "gaokaobaobei/userbackup/delete",
                    contentType: "application/json",
				    data: JSON.stringify(ids),
				    success: function(r){
						if(r.code == 0){
							alert('操作成功', function(index){
								$("#jqGrid").trigger("reloadGrid");
								vm.reload();
							});
						}else{
							alert(r.msg);
						}
					}
				});
			});
		},
		getInfo: function(id){
			$.get(baseURL + "gaokaobaobei/userbackup/info/"+id, function(r){
                vm.userBackup = r.userBackup;
            });
		},
		reload: function (event) {
			vm.showList = true;
            vm.getnumber();
			var page = $("#jqGrid").jqGrid('getGridParam','page');
			$("#jqGrid").jqGrid('setGridParam',{
                postData:{'type': vm.type},
                page:page
            }).trigger("reloadGrid");
		}
	}
});